<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>登陆</title>
</head>
<body>
<h1>登录页面</h1>
<hr/>
<p>
    <label>用户名：</label>
    <input id="username" type="text"/>
</p>
<p>
    <label>密码：</label>
    <input id="password" type="password"/>
</p>
<p>
    <button id="sub">登录</button>
</p>
</body>
<script src="http://code.jquery.com/jquery-1.8.0.min.js"></script>
<script src="https://cdn.bootcss.com/jquery-cookie/1.4.1/jquery.cookie.js"></script>
<script>
    $('#sub').click(function () {
        login();
    });
    function login() {
        var username = $('#username').val();
        var password = $('#password').val();
        $.ajax({
            url:'/login',
            type:'POST',
            data:{
              'username':username,
              'password':password
            },
            dataType:'json',
            success:function (res) {
                console.log(res);
                if (res.code == '0'){
                    $.cookie('token',res.data);
                    console.log($.cookie('token'));
                    window.location.href = '/view/index';
                }
            }
        });
    }
</script>
</html>